package com.trc202.CS350;
//Term Project Ted Chandler and Daniel Moore
public class MemorySegment {
	
	private int segmentNum = 0;
	private int size = 0;
	private int wasted = 0;
	private boolean inUse = false;
	
	public MemorySegment(int segmentNum, int size){
		this.segmentNum = segmentNum;
		this.size = size;
	}
	
	/**
	 * 
	 * @param neededSpace Space required in MB or 0 to stop using this segment
	 *
	 */
	public void setMBUsed(int neededSpace){
		if(neededSpace > size){
			throw new RuntimeException();
		}else if(neededSpace == 0){
			inUse = false;
			wasted = 0;
		}else{
			inUse = true;
			wasted = size - neededSpace;
		}
	}

	/**
	 * @return Segment Number
	 */
	public int getSegmentNum() {
		return segmentNum;
	}

	/**
	 * @return Total size of ram in MB
	 */
	public int getSize() {
		return size;
	}

	/**
	 * @return Unused ram in this segment in MB
	 */
	public int getWasted() {
		return wasted;
	}

	/**
	 * @return True if there is currently a process in memory
	 */
	public boolean isInUse() {
		return inUse;
	}
	
	@Override
	public String toString(){
		return "Segment Number: " + segmentNum + " Size: " + size + " Wasted: " + wasted + " Used: " + inUse; 
	}
}
